<div>
    <div class="col-lg-12">
        <section class="panel">
            <div class="panel-body">
                <form class="form-horizontal adminex-form" onsubmit="return false;">
                    <div class="base">
                        <div class="base-left">
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span class="red-start">*</span> 竞猜类型</label>
                                <div class="col-sm-4">
                                    <select name="type"  id='type' class="form-control">
                                        <?php foreach ($this->typeArr as $key => $item){?>
                                        <option value="<?php echo $key;?>"><?php echo $item;?></option>
                                    <?php }?>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label"><span class="red-start">*</span> 预猜标题</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" name="title" placeholder="请输入预猜标题"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">预猜A队进球数</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" name="score_a" value="0" placeholder="请输入预猜A队进球数">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">预猜B队进球数</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" name="score_b" value="0" placeholder="请输入预猜B队进球数">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="modal-footer" style="text-align: left;margin-left: 6%;">
                                    <button class="btn btn-success" type="button"  onclick="subSave()">保存</button>
                                    <button class="btn btn-default" type="button" style="background-color:#CCCCCC;border-color:#CCCCCC;" data-dismiss="modal" aria-hidden="true">
                                        <a href="#" onclick="window.history.back()" style="text-decoration: none;">取消</a></button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </section>
    </div>
</div>

<script>
    function subSave() {
        var type = $("#type").val();
        var title =  $("input[name='title']").val();
        var score_a = $("input[name='score_a']").val();
        var score_b = $("input[name='score_b']").val();

        if(!type){
            layer.alert('请选择竞猜类型');
            return false;
        }

        if(!title){
            layer.alert('请填写预猜标题');
            return false;
        }
        if(parseInt(type) == 3){
            if(score_a == ''){
                layer.alert('请填写预猜A队进球数');
                return false;
            }
            if(score_b == ''){
                layer.alert('请填写预猜B队进球数');
                return false;
            }
        }
        var index = layer.msg('保存中...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,offset: '0px', time:1000000});
        $.ajax({
            url  : '/play/setting-add',
            type : 'post',
            data : {
                type:type,
                title:title,
                score_a:score_a,
                score_b:score_b
            },
            dataType : 'json',
            success : function (msg) {
                if (msg.code == 200) {
                    layer.close(index);
                    layer.alert('添加成功',function () {
                        //location.href = '/play/setting';
                        window.location.reload();
                    })
                } else{
                    layer.close(index);
                    layer.alert('添加失败');
                }
            }
        });
    }
</script>